package com.mbrs.web;

import com.mbrs.aggr.MyUserBan;
import com.mbrs.aggr.MyUserInfo;
import com.mbrs.msg.MsgSender;
import com.mbrs.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private LoginService loginService;

    @Autowired
    private MsgSender msgSender;

    @RequestMapping("/ban")
    @ResponseBody
    public CommonVO ban(long userId, long liftTime, String banTip,
                        String banReason) {
        MyUserBan myUserBan = loginService.ban(userId, liftTime, banTip,
                banReason);
        if (myUserBan == null) {
            return CommonVO.unsuccess("canNotBan");
        }
        return CommonVO.success();
    }

    @RequestMapping("/liftban")
    @ResponseBody
    public CommonVO liftban(long userId, String liftReason) {
        MyUserBan myUserBan = loginService.liftBan(userId);
        if (myUserBan == null) {
            return CommonVO.unsuccess("canNotLiftBan");
        }
        return CommonVO.success();
    }

    @RequestMapping("/extenduser")
    @ResponseBody
    public CommonVO extenduser(long userId, String extend) {
        loginService.setUserInfoExtend(userId, extend);
        msgSender.sendProcess(false);
        return CommonVO.success();
    }

    @RequestMapping("/userinfo")
    @ResponseBody
    public CommonVO userinfo(long userId) {
        MyUserInfo userInfo = loginService.getUserInfo(userId);
        return CommonVO.success(userInfo);
    }

}
